package com.SmartClassroom.system.service.impl;

import com.SmartClassroom.system.common.ErrorCode;
import com.SmartClassroom.system.exception.BusinessException;
import com.SmartClassroom.system.mapper.LeaveRequestMapper;
import com.SmartClassroom.system.model.domain.LeaveRequest;
import com.SmartClassroom.system.model.dto.leave.LeaveQueryRequest;
import com.SmartClassroom.system.model.vo.LeaveRequestVO;
import com.SmartClassroom.system.service.LeaveRequestService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author baijiayu
* @description 针对表【LeaveRequest】的数据库操作Service实现
* @createDate 2024-11-19 11:01:52
*/
@Service
public class LeaveRequestServiceImpl extends ServiceImpl<LeaveRequestMapper, LeaveRequest>
    implements LeaveRequestService {

    @Resource
    private LeaveRequestMapper leaveRequestMapper;

    @Override
    public Page<LeaveRequestVO> getQueryWrapper(Page<LeaveRequestVO> pageParam,LeaveQueryRequest leaveQueryRequest) {
        if (leaveQueryRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"请求参数为空");
        }
        // 自定义分页查询
        List<LeaveRequestVO> leaveRequestVOList = leaveRequestMapper.page(pageParam,leaveQueryRequest);
        if (leaveRequestVOList == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(leaveRequestVOList);
        return pageParam;
    }

    @Override
    public Page<LeaveRequestVO> getQueryById(Page<LeaveRequestVO> pageParam, LeaveQueryRequest leaveQueryRequest, Long studentId) {
        if (leaveQueryRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR,"请求参数为空");
        }
        // 自定义分页查询
        List<LeaveRequestVO> leaveRequestVOList = leaveRequestMapper.getQueryById(pageParam,leaveQueryRequest,studentId);
        if (leaveRequestVOList == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"查询失败");
        }
        // 设置分页结果
        pageParam.setRecords(leaveRequestVOList);
        return pageParam;
    }
}




